import QtQuick 1.0
import InvMA 1.0

FocusScope {
    id: root

    property alias font: textEdit.font

    property alias cursorPosition: textEdit.cursorPosition
    property alias text: textEdit.text
    property bool readOnly: false

    property bool __readonlyIsGray: true //not implement - do it

    function copy() {
        textEdit.copy()
    }

    function paste() {
        textEdit.paste()
    }

    function cut() {
        textEdit.cut()
    }

    function positionAt(x, y) {
        var p = mapToItem(textEdit, x, y);
        return textEdit.positionAt(p.x, p.y)
    }

    onActiveFocusChanged: {
        if (activeFocus && !readOnly) {
            wrapperTE.border.width = 2
            textEdit.openSoftwareInputPanel();
            //repositionTimer.running = true;
        } else if (!activeFocus) {
            wrapperTE.border.width = 1
            if (!readOnly) {
                textEdit.closeSoftwareInputPanel();
            }
        }
    }

    Rectangle {
        id: wrapperTE
        anchors.verticalCenter: parent.verticalCenter
        anchors.left: parent.left;
        color: "white"
        border.color: __readonlyIsGray == true ? (root.readOnly == true ? "gray" : "blue") : "blue"
        radius: 12
        width: parent.width// - 2*anchors.leftMargin
        height: parent.height
        clip: true
        smooth: true

        TextInput {
            id: textEdit
            readOnly: root.readOnly
            anchors.verticalCenter: parent.verticalCenter
            anchors.left: parent.left; anchors.leftMargin: 8
            width: parent.width - 2*anchors.leftMargin
            height: parent.height*0.75
            font.pixelSize: 0.6*parent.height
            color: __readonlyIsGray == true ? (root.readOnly == true ? "gray" : "black") : "black"

            InverseMouseArea {
                anchors.fill: parent
                enabled: root.activeFocus
                onClickedOutside: {
                    root.parent.focus = true;
                }
            }
        } //TextInput
    }


}
